// pages/Vip/older/older.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		header: "",
		http: getApp().globalData.map,
		ticket: '暂无可用优惠劵',
		map: '请选择服务门店',
		uid: '', 
		num: '',
		price: '',
		value: '',
		txt:'',
		qid:'',
		qian:''
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onShow() {
		console.log(this.data)
		if (this.data.value != '') {
			this.setData({
				map: this.data.value[1]
			})
		}
	},
	deal() {
		if (this.data.value!=''){
			wx.request({
				url:getApp().globalData.http +'action=buyCard&cardID='+this.data.header.ID+'&uid='+this.data.uid+'&qid='+this.data.qid+'&shopid='+this.data.value[0],
				success: (e) => {
					console.log(e)
					wx.navigateTo({
						url:'../deal/deal?orderCode='+e.data.data.orderCode+'&id='+e.data.data.ID+"&totalprice="+e.data.data.totalprice
					})
				}
			})
			
		}else{
			wx.showToast({
				icon:"none",
				title:'请选择门店'
			})
		}
	},
	onLoad: function(options) {
		console.log(options)
		let a = ''
		let _this = this
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				console.log(e.data)
				wx.request({
					url: getApp().globalData.http + 'action=membersSingle&id=' + options.id,
					success: (res) => {
						console.log(res)
						if (e.data.Vip == 0) {
							a = res.data.data.YPrice
						} else {
							a = res.data.data.YPrice - res.data.data.Frprice
						}

						_this.setData({
							header: res.data.data,
							price: a,
							uid:e.data.uid
						})
						wx.request({
							url:getApp().globalData.http+'action=kyQuan&uid='+e.data.uid+'&qtype=2&price='+res.data.data.YPrice+'&goodids='+res.data.data.ID,
							success: (e) => {
								console.log(e)
								this.setData({
									list:e.data.data
								})
							}
						})
					}
				})

			}
		})
	},
	moon(){
		if(this.data.list.length>0){
			wx.navigateTo({
				url:'../../place/quan/quan?qtype=2&price='+this.data.price+'&goodids='+this.data.header.id
			})
		}else{
			wx.showToast({
				icon:'none',
				title:'暂无可用优惠券'
			})
		}
	}
})
